home *** CD-ROM | disk | FTP | other *** search
- Path: alfa.ist.utl.pt!l40128
- From: l40128@alfa.ist.utl.pt (delphis)
- Newsgroups: comp.lang.c
- Subject: Binary files ?
- Date: 22 Feb 1996 09:53:18 GMT
- Organization: Instituto Superior Tecnico
- Message-ID: <4gheee$bvr@ci.ist.utl.pt>
- NNTP-Posting-Host: alfa.ist.utl.pt
- X-Newsreader: TIN [version 1.2 PL2]
-
-
-
-
-
- Greetings from a frustrated c programmer!
- I program in c a couple of years but i never figure out this basic
- question : how to work with binary files ? basically, what i want to do
- is writing a matrix to a file and read it back but when i try the
- following code in dos the matrix comes all gobled, but works fine in unix!
- Can anyone tell me whats wrong with this ? I have been using text files
- and they dont give any troble at all!
-
- Obrigadissimo!
-
-
-
-
- # include <stdio.h>
-
-
- void main()
- {
-
- /*write file*/
- int n;
- unsigned char mat[200];
- FILE *f=fopen("teste","w"); /*do i have to use the CREATE before this ?*/
- for (n=0;n<200;n++) mat[n]=n; /*init matrix*/
- fwrite(mat,200,1,f);
- fclose(f);
-
- /*reset matrix*/
- for (n=0;n<200;n++) mat[n]=0;
-
- /*read file*/
- f=fopen("teste","r");
- fread(mat,200,1,f);
- fclose(f);
- for (n=0;n<200;n++) printf("%d ",mat[n]);/*print it*/
- }
-
-
-
- // The main difference between man and animal is that man possesses the \\
- //hability to think he is rational... \\
- E-mail : l40128@alfa.ist.utl.pt
-
-